package com.yuncommunity.runcircle.conf;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * Created by oldfeel on 11/24/15.
 */
public class UserInfo {
    private static UserInfo userInfo;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    public static UserInfo getInstance(Context context) {
        if (userInfo == null || userInfo.sp == null || userInfo.editor == null) {
            userInfo = new UserInfo();
            userInfo.sp = PreferenceManager.getDefaultSharedPreferences(context);
            userInfo.editor = userInfo.sp.edit();
        }
        return userInfo;
    }

    public static UserInfo getInstance() {
        if (userInfo == null) {
            userInfo = new UserInfo();
        }
        return userInfo;
    }

    public int getUserId() {
        return 1;
    }

    /**
     * 体重
     *
     * @return
     */
    public double getWeight() {
        return 60;
    }

    public int getStep() {
        return 0;
    }

    public void clearTimeAndState() {
        editor.putInt("time", 0);
        editor.putInt("state", 1);
        editor.commit();
    }

    public void saveTimeAndState(int time, int state) {
        editor.putInt("time", time);
        editor.putInt("state", state);
        editor.commit();
    }

    public int getTime() {
        return sp.getInt("time", 0);
    }

    public int getState() {
        return sp.getInt("state", 1);
    }
}
